﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cls_tb_position_element_HOADON
/// </summary>
public class cls_tb_position_element_HOADON
{
    #region Property
    public struct ObjectPositionElementHoaDon
    {
        public string name_element;
        public int ID_GROUP;
        public int x;
        public int y;
        public int width;
        public int visible;        
    } 
    #endregion
    public static ObjectPositionElementHoaDon InstanceObject;
    
    public static ObjectPositionElementHoaDon XR_F_KyHieuHD;
    public static ObjectPositionElementHoaDon XR_F_STT;
    public static ObjectPositionElementHoaDon XR_F_SoHD;
    public static ObjectPositionElementHoaDon XR_ngay;
    public static ObjectPositionElementHoaDon XR_thang;
    public static ObjectPositionElementHoaDon XR_nam;
    public static ObjectPositionElementHoaDon XR_nguoimuahang_hoten;
    public static ObjectPositionElementHoaDon XR_donvi;
    public static ObjectPositionElementHoaDon XR_diachi;
    public static ObjectPositionElementHoaDon XR_taikhoan;
    public static ObjectPositionElementHoaDon XR_MST;
    public static ObjectPositionElementHoaDon XR_MST1;
    public static ObjectPositionElementHoaDon XR_MST2;
    public static ObjectPositionElementHoaDon XR_MST3;
    public static ObjectPositionElementHoaDon XR_MST4;
    public static ObjectPositionElementHoaDon XR_MST5;
    public static ObjectPositionElementHoaDon XR_MST6;
    public static ObjectPositionElementHoaDon XR_MST7;
    public static ObjectPositionElementHoaDon XR_MST8;
    public static ObjectPositionElementHoaDon XR_MST9;
    public static ObjectPositionElementHoaDon XR_MST10;
    public static ObjectPositionElementHoaDon XR_MST11;
    public static ObjectPositionElementHoaDon XR_MST12;
    public static ObjectPositionElementHoaDon XR_MST13;
    public static ObjectPositionElementHoaDon XR_MST14;
    public static ObjectPositionElementHoaDon XR_HTTT;
    public static ObjectPositionElementHoaDon Line_1;
    public static ObjectPositionElementHoaDon Line_2;
    public static ObjectPositionElementHoaDon Line_3;
    public static ObjectPositionElementHoaDon Line_4;
    public static ObjectPositionElementHoaDon XRstt;
    public static ObjectPositionElementHoaDon XRtenhanghoa;
    public static ObjectPositionElementHoaDon XRdonvitinh;
    public static ObjectPositionElementHoaDon XRsoluong;
    public static ObjectPositionElementHoaDon XRdongia;
    public static ObjectPositionElementHoaDon XRthanhtien;
    public static ObjectPositionElementHoaDon XR_congtienhang;
    public static ObjectPositionElementHoaDon XR_thue;
    public static ObjectPositionElementHoaDon XR_GTGT;
    public static ObjectPositionElementHoaDon XR_thanhtien;
    public static ObjectPositionElementHoaDon XR_tienbangchu;
    public static ObjectPositionElementHoaDon XR_nguoimuahang_kyten;
    public static ObjectPositionElementHoaDon XR_nguoibanhang;
    public static ObjectPositionElementHoaDon Dx;
    public static ObjectPositionElementHoaDon Lx;
    public static ObjectPositionElementHoaDon A_testRSwStt1;

    public cls_tb_position_element_HOADON()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    
    public static DataTable GetByNameelement_F_MACN(string name_element,string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[2];
        para[0] = new SqlParameter("@name_element", name_element);
        para[1] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tb_position_element_HOADON_GetByNameelement_F_MACN", para);
        }
        catch { }
        return dt;
    }
    public static DataTable GetByF_MACN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tb_position_element_HOADON_GetByF_MACN", para);
        }
        catch { }
        return dt;
    }
    public static string Update(string name_element, string F_MACN, int pos_x, int pos_y, int width_element, int visible_element)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { name_element, F_MACN, pos_x, pos_y, width_element, visible_element };
        string[] parameters = { "@name_element", "@F_MACN", "@pos_x", "@pos_y", "@width_element", "@visible_element" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tb_position_element_HOADON_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static void ReadPostion(string F_MACN)
    {
        int ID_GROUP = 0;
        ID_GROUP = cls_tb_GROUPCHINHANH_XUATHOADON.getID_GROUPbyF_MACN(F_MACN);
        DataTable dt = new DataTable();
        dt = GetByF_MACN(F_MACN);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name_element = "";
                name_element = dt.Rows[i]["name_element"].ToString();
                int pos_x = 0;
                int pos_y = 0;
                int width_element = 0;
                int visible_element = 0;
                try {
                    pos_x = int.Parse(dt.Rows[i]["pos_x"].ToString());
                }
                catch { }
                try
                {
                    pos_y = int.Parse(dt.Rows[i]["pos_y"].ToString());
                }
                catch { }
                try
                {
                    width_element = int.Parse(dt.Rows[i]["width_element"].ToString());
                }
                catch { }
                try
                {
                    visible_element = int.Parse(dt.Rows[i]["visible_element"].ToString());
                }
                catch { }
                InstanceObject.ID_GROUP = ID_GROUP;
                InstanceObject.x = pos_x;
                InstanceObject.y = pos_y;
                InstanceObject.width = width_element;
                InstanceObject.visible = visible_element;
                //-------
                if (name_element == "Line_1")
                {
                    InstanceObject.name_element = name_element;
                    Line_1 = SetForElement(Line_1);
                }
                //-------
                if (name_element == "Line_2")
                {
                    InstanceObject.name_element = name_element;
                    Line_2 = SetForElement(Line_2);
                }
                //-------
                if (name_element == "Line_3")
                {
                    InstanceObject.name_element = name_element;
                    Line_3 = SetForElement(Line_3);
                }
                //-------
                if (name_element == "Line_4")
                {
                    InstanceObject.name_element = name_element;
                    Line_4 = SetForElement(Line_4);
                }
                //-------
                if (name_element == "XR_congtienhang")
                {
                    InstanceObject.name_element = name_element;
                    XR_congtienhang = SetForElement(XR_congtienhang);
                }
                //-------
                if (name_element == "XR_diachi")
                {
                    InstanceObject.name_element = name_element;
                    XR_diachi = SetForElement(XR_diachi);
                }
                //-------
                if (name_element == "XR_donvi")
                {
                    InstanceObject.name_element = name_element;
                    XR_donvi = SetForElement(XR_donvi);
                }
                //-------
                if (name_element == "XR_F_KyHieuHD")
                {
                    InstanceObject.name_element = name_element;
                    XR_F_KyHieuHD = SetForElement(XR_F_KyHieuHD);
                }
                //-------
                if (name_element == "XR_F_SoHD")
                {
                    InstanceObject.name_element = name_element;
                    XR_F_SoHD = SetForElement(XR_F_SoHD);
                }
                //-------
                if (name_element == "XR_F_STT")
                {
                    InstanceObject.name_element = name_element;
                    XR_F_STT = SetForElement(XR_F_STT);
                }
                //-------
                if (name_element == "XR_GTGT")
                {
                    InstanceObject.name_element = name_element;
                    XR_GTGT = SetForElement(XR_GTGT);
                }
                //-------
                if (name_element == "XR_HTTT")
                {
                    InstanceObject.name_element = name_element;
                    XR_HTTT = SetForElement(XR_HTTT);
                }
                //-------
                if (name_element == "XR_MST")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST = SetForElement(XR_MST);
                }
                //-------
                if (name_element == "XR_MST1")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST1 = SetForElement(XR_MST1);
                }
                //-------
                if (name_element == "XR_MST10")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST10 = SetForElement(XR_MST10);
                }
                //-------
                if (name_element == "XR_MST11")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST11 = SetForElement(XR_MST11);
                }
                //-------
                if (name_element == "XR_MST12")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST12 = SetForElement(XR_MST12);
                }
                //-------
                if (name_element == "XR_MST13")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST13 = SetForElement(XR_MST13);
                }
                //-------
                if (name_element == "XR_MST14")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST14 = SetForElement(XR_MST14);
                }
                //-------
                if (name_element == "XR_MST2")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST2 = SetForElement(XR_MST2);
                }
                //-------
                if (name_element == "XR_MST3")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST3 = SetForElement(XR_MST3);
                }
                //-------
                if (name_element == "XR_MST4")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST4 = SetForElement(XR_MST4);
                }
                //-------
                if (name_element == "XR_MST5")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST5 = SetForElement(XR_MST5);
                }
                //-------
                if (name_element == "XR_MST6")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST6 = SetForElement(XR_MST6);
                }
                //-------
                if (name_element == "XR_MST7")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST7 = SetForElement(XR_MST7);
                }
                //-------
                if (name_element == "XR_MST8")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST8 = SetForElement(XR_MST8);
                }
                //-------
                if (name_element == "XR_MST9")
                {
                    InstanceObject.name_element = name_element;
                    XR_MST9 = SetForElement(XR_MST9);
                }
                //-------
                if (name_element == "XR_nam")
                {
                    InstanceObject.name_element = name_element;
                    XR_nam = SetForElement(XR_nam);
                }
                //-------
                if (name_element == "XR_ngay")
                {
                    InstanceObject.name_element = name_element;
                    XR_ngay = SetForElement(XR_ngay);
                }
                //-------
                if (name_element == "XR_nguoibanhang")
                {
                    InstanceObject.name_element = name_element;
                    XR_nguoibanhang = SetForElement(XR_nguoibanhang);
                }
                //-------
                if (name_element == "XR_nguoimuahang_hoten")
                {
                    InstanceObject.name_element = name_element;
                    XR_nguoimuahang_hoten = SetForElement(XR_nguoimuahang_hoten);
                }
                //-------
                if (name_element == "XR_nguoimuahang_kyten")
                {
                    InstanceObject.name_element = name_element;
                    XR_nguoimuahang_kyten = SetForElement(XR_nguoimuahang_kyten);
                }
                //-------
                if (name_element == "XR_taikhoan")
                {
                    InstanceObject.name_element = name_element;
                    XR_taikhoan = SetForElement(XR_taikhoan);
                }
                //-------
                if (name_element == "XR_thang")
                {
                    InstanceObject.name_element = name_element;
                    XR_thang = SetForElement(XR_thang);
                }
                //-------
                if (name_element == "XR_thanhtien")
                {
                    InstanceObject.name_element = name_element;
                    XR_thanhtien = SetForElement(XR_thanhtien);
                }
                //-------
                if (name_element == "XR_thue")
                {
                    InstanceObject.name_element = name_element;
                    XR_thue = SetForElement(XR_thue);
                }
                //-------
                if (name_element == "XR_tienbangchu")
                {
                    InstanceObject.name_element = name_element;
                    XR_tienbangchu = SetForElement(XR_tienbangchu);
                }
                //-------
                if (name_element == "XRdongia")
                {
                    InstanceObject.name_element = name_element;
                    XRdongia = SetForElement(XRdongia);
                }
                //-------
                if (name_element == "XRdonvitinh")
                {
                    InstanceObject.name_element = name_element;
                    XRdonvitinh = SetForElement(XRdonvitinh);
                }
                //-------
                if (name_element == "XRsoluong")
                {
                    InstanceObject.name_element = name_element;
                    XRsoluong = SetForElement(XRsoluong);
                }
                //-------
                if (name_element == "XRstt")
                {
                    InstanceObject.name_element = name_element;
                    XRstt = SetForElement(XRstt);
                }
                //-------
                if (name_element == "XRtenhanghoa")
                {
                    InstanceObject.name_element = name_element;
                    XRtenhanghoa = SetForElement(XRtenhanghoa);
                }
                //-------
                if (name_element == "XRthanhtien")
                {
                    InstanceObject.name_element = name_element;
                    XRthanhtien = SetForElement(XRthanhtien);
                }
                //-------
                if (name_element == "Dx")
                {
                    InstanceObject.name_element = name_element;
                    Dx = SetForElement(Dx);
                }
                //-------
                if (name_element == "Lx")
                {
                    InstanceObject.name_element = name_element;
                    Lx = SetForElement(Lx);
                }
                //-------
                if (name_element == "A_testRSwStt1")
                {
                    InstanceObject.name_element = name_element;
                    A_testRSwStt1 = SetForElement(A_testRSwStt1);
                }
            }
        }
    }
    public static ObjectPositionElementHoaDon SetForElement(ObjectPositionElementHoaDon objElementSeted)
    {
        objElementSeted.ID_GROUP = InstanceObject.ID_GROUP;
        objElementSeted.name_element = InstanceObject.name_element;
        objElementSeted.x = InstanceObject.x;
        objElementSeted.y = InstanceObject.y;
        objElementSeted.width = InstanceObject.width;
        objElementSeted.visible = InstanceObject.visible;

        return objElementSeted;
    }
}